<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>投股中心</title>
    <link rel="stylesheet" href="css/jquery.emojiarea.css"/>
    <link type="text/css" rel="stylesheet" href="css/style.css">
</head>
<body class="uf uf-ver">

<!--header-->
<div id="header">
    <div class="center ub">
        <div class="navLeft Btn" onclick="window.history.go(-1);"></div>
        <h1 id="title" class="ub-f"></h1>

        <div class="navRight"></div>
    </div>
</div>

<!--content-->
<div id="content" class="uf-f bgc">

    <!--<div class="chatTime"><span>10:52:34</span></div>-->

    <div class="chat chatLeft ub">
        <div class="chatImg"><img src="img/src/PicServer.png"></div>
        <div class="ub-f chatTxt">
            <div class="chatAngle"></div>
            <span>老师说的这支股票最近以来涨的较高的一支</span>
        </div>
    </div>
    <div class="chat chatLeft ub">
        <div class="chatImg"><img src="img/src/PicServer.png"></div>
        <div class="ub-f chatTxt">
            <div class="chatAngle"></div>
            <span>涨了</span>
        </div>
    </div>
    <div class="chat chatRight ub">
        <div class="ub-f chatTxt ub ub-pe">
            <div class="chatAngle"></div>
            <span>老师说的太准了</span>
        </div>
        <div class="chatImg"><img src="img/src/PicCustomer.png"></div>
    </div>


</div>

<div id="chatFooter">
    <form class="ub ub-ac chatFooter">
        <div class="ub-f inputArea">
            <textarea id="chatVal" class="emojis-wysiwyg"></textarea>
        </div>
        <div class="chatIcon send" onclick="sendMsg();"></div>
        <div class="chatIcon emoSend"></div>
    </form>

</div>

<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/layer_mobile/layer.js"></script>
<script type="text/javascript" src="js/jquery.emojiarea.js"></script>
<script type="text/javascript" src="js/emojis.js"></script>
<script type="text/javascript" src="js/common.js"></script>
<script>
    var $input = $('#chatVal'), $inputDiv, $container = $('#content');

    (function () {//设置标题名称
        var tag = getLocHrefStr('tag'), title = '';
        switch (tag) {
            case 'server':
                title = '联系客服';
                break;
            case 'teacher':
                title = '联系老师';
                break;
        }
        $('#title').html(title);
    })();

    $(document).ready(function () {
        scrollLast();//控制聊天区域滚动条到底部
        $('.emojis-wysiwyg').emojiarea({wysiwyg: true});//初始化输入框，绑定表情
        $inputDiv = $('.emoji-wysiwyg-editor');
        $inputDiv.on('keydown', function (event) {//绑定按键
            var e = event || window.event || arguments.callee.caller.arguments[0],
                    keyCode = e.keyCode;
            if (keyCode == '13' && e.ctrlKey) {//ctrl+Enter发送
                e.preventDefault();
                sendMsg();
            }
        });

        scrollBar();//控制内容向上或向下滑动时隐藏或显示顶部和底部
    });

    function scrollLast() {//滚动条到最底部
        $container.scrollTop($container[0].scrollHeight);
    }

    function addMsg(str, p) {//向聊天区域添加消息，p-'left',左边对话框，不传默认为右边对话框
        var msg = '<div class="chat chatRight ub">' +
                '<div class="ub-f chatTxt ub ub-pe">' +
                '<div class="chatAngle"></div>' +
                '<span>' + str + '</span>' +
                '</div>' +
                '<div class="chatImg"><img src="img/src/PicCustomer.png"></div>' +
                '</div>';
        if (p && p == 'left') {//左边对话框
            msg = '<div class="chat chatLeft ub">' +
                    '<div class="chatImg"><img src="img/src/PicServer.png"></div>' +
                    '<div class="ub-f chatTxt">' +
                    '<div class="chatAngle"></div>' +
                    '<span>' + str + '</span>' +
                    '</div>' +
                    '</div>';
        }
        $container.append(msg);
    }

    function sendMsg() {//发送消息
        var str = $.trim($input.val());
        if (str) {
            addMsg(strToHtmlEmoji(str));
            scrollLast();//控制聊天区域滚动条到底部
        } else {
            //提示
            layer.open({
                content: '请输入内容'
                , skin: 'msg'
                , time: 2 //2秒后自动关闭
            });
        }
        $input.val('');//清空输入框
        $inputDiv.html('');//清空输入框
    }

</script>
</body>
</html>